package sqlite

import (
	"database/sql"
	"sync"

	_ "github.com/mattn/go-sqlite3"
)

type SQLiteHelper struct {
	db   *sql.DB
	lock sync.Mutex
}

func NewSQLiteHelper() *SQLiteHelper {
	rval := &SQLiteHelper{}
	return rval
}

func (this *SQLiteHelper) OpenFile(file string) error {
	_db, err := sql.Open("sqlite3", file)
	if err != nil {
		return err
	}
	this.db = _db
	return nil
}

func (this *SQLiteHelper) Lock() {
	this.lock.Lock()
}

func (this *SQLiteHelper) UnLock() {
	this.lock.Unlock()
}

func (this *SQLiteHelper) Query(query string, args ...interface{}) (*sql.Rows, error) {
	return this.db.Query(query, args...)
}

func (this *SQLiteHelper) Exec(query string, args ...interface{}) (sql.Result, error) {
	return this.db.Exec(query, args...)
}
